package com.cts.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cts.entity.Blog;
import com.cts.model.vo.*;
import com.cts.service.BlogService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @projectName: CBlog
 * @package: com.cts.controller.admin
 * @className: BlogController
 * @author: chentongsheng
 * @description: TODO
 * @date: 2023/2/20 22:06
 * @version: 1.0
 */
@RestController
@RequestMapping("/blog")
public class BlogController {

    @Autowired
    BlogService blogService;

    @RequestMapping("getBlogs")
    @ApiOperation("获取首页文章")
    public Result getBlogs(@RequestParam(required = false) String type, @RequestParam(required = false) String value, Integer pageNo, Integer pageSize) {
        PageResultVO<BlogInfoVO> blogs = blogService.getBlogs(type, value, pageNo, pageSize);
        return Result.ok("查询成功", blogs);
    }

    @RequestMapping("getRandomBlogs")
    @ApiOperation("获取随机文章")
    public Result getRandomBlogs() {
        List<RandomBlogVO> randomBlogs = blogService.getRandomBlogs();
        return Result.ok("查询成功",randomBlogs);
    }

    @RequestMapping("getBlogById")
    @ApiOperation("获取博客详情")
    public Result getBlogById(@RequestParam Long id) {
        Blog blog = blogService.getBlogDetail(id);
        return Result.ok("查询成功",blog);
    }

    @RequestMapping("getBlogTimeLine")
    @ApiOperation("获取归档文章")
    public Result getBlogTimeLine() {

        Map<String, Object> blogTimeLine = blogService.getBlogTimeLine();
        return Result.ok("查询成功",blogTimeLine);
    }
}
